package com.xiyu.service.service.statistics;

import com.xiyu.service.convert.statistics.StatisticsMailConvert;
import com.xiyu.service.repository.mailbox.mail.MailboxMailRepository;
import com.xiyu.service.service.system.user.UserService;
import com.xiyu.service.vo.statistics.statisticsMail.StatisticsMailReceiveSendQueryOutput;
import com.xiyu.service.vo.statistics.statisticsMail.StatisticsMailReceiveSendQueryInput;
import jakarta.annotation.Resource;
import org.babyfish.jimmer.sql.ast.tuple.Tuple5;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import java.time.LocalDateTime;
import java.util.List;

import static com.xiyu.service.framework.exception.util.ServiceExceptionUtil.exception;
import static com.xiyu.service.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;

/**
 * 邮件统计 Service 实现类
 */
@Service
@Validated
public class StatisticsMailServiceImpl implements StatisticsMailService {

    @Resource
    MailboxMailRepository mailboxMailRepository;

    @Resource
    UserService userService;


    @Override
    public List<StatisticsMailReceiveSendQueryOutput> receiveSendQuery(StatisticsMailReceiveSendQueryInput inputVO) {
        List<Long> ownerUserIds = userService.getOwnerUserIds(getLoginUserId());
        List<Tuple5<Long, LocalDateTime, Long, Long, Long>> receiveSendInfos = mailboxMailRepository.receiveSendQuery(ownerUserIds, inputVO);
        return StatisticsMailConvert.INSTANCE.dealConvertQueryOutputConvert(receiveSendInfos);
    }

}
